package com.platform.server.util;


import org.junit.Test;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

public class AlidayuSmsTest {
	
	private String url = "https://eco.taobao.com/router/rest";
	private String appkey = "23650096";
	private String secret ="4e1b456c202287b3587380665af391ee";
	private String productName = "蓝小雨";
	
	/**
	 * 模拟发送短信
	 * @throws ApiException 
	 */
	@Test
	public void getAuthCode(){
		String phoneNo = "17603016519";
		
		String smsFreeSignName = "注册验证";
		String templateCode = "SMS_48670131";
		
		StringBuffer sBuffer = new StringBuffer();
		//产生随机验证码
		for(int i = 0; i < 6; i++){
			int k = (int) (10*(Math.random()));
			sBuffer.append(k);
		}
		try{
			TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
			AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
			req.setExtend( "短息验证" );
			req.setSmsType( "normal" );
			//短信签名
			req.setSmsFreeSignName(smsFreeSignName);
			
			//验证码${code}，您正在注册成为${product}用户，感谢您的支持！
			//{code:'123456',product:'蓝小雨'}
			//对应短信模板变量
			req.setSmsParamString( "{code:'"+sBuffer+"',product:'"+productName+"'}" );
			req.setRecNum( phoneNo );
			req.setSmsTemplateCode(templateCode);
			AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
			System.out.println(rsp.getBody());
			/*{
			    "alibaba_aliqin_fc_sms_num_send_response": {
			        "result": {
			            "err_code": "0",
			            "model": "106544979033^1108899471487",
			            "success": true
			        },
			        "request_id": "2lv4is9t1zgk"
			    }
			}*/
			if(rsp.isSuccess()){				
				String code = rsp.getResult().getModel();
				System.out.println(code);
			}
		}catch (Exception e) {
		}
	}
}

/*//**
 * 短信验证码查询
 *//*
@Test
public void testAlidayu() throws ApiException {
	String url = "https://eco.taobao.com/router/rest";
	String appkey = "23704003";
	String secret = "893682e454b6d785d992d19e44574e18";
	String phoneNo = "17603016519";
	
	// 阿里大于获取验证码
	TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);

	AlibabaAliqinFcSmsNumQueryRequest req = new AlibabaAliqinFcSmsNumQueryRequest();

	// 短信发送流水，可从短信发送接口response 中的model 获取
	req.setBizId("1234^1234");

	// 接收短信的手机号码
	req.setRecNum(phoneNo);

	// 短信发送日期（支持最近30天记录查询）格式yyyyMMdd
	String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
	req.setQueryDate(date);
	// 当前页
	req.setCurrentPage(1L);
	// 每页大小，最大值50
	req.setPageSize(10L);
	// 执行验证
	AlibabaAliqinFcSmsNumQueryResponse rsp = client.execute(req);
	System.out.println(rsp.getBody());
}*/
